using System;
using log4net;
using Triton.Bot.Settings;
using Triton.Common;
using Triton.Common.LogUtilities;
using Triton.Game.Mapping;

namespace Triton.Bot
{
	public static class Utility
	{
		private static readonly ILog ilog_0;

		public static readonly Random Random;

		public static void smethod_0(object object_0)
		{
			IConfigurable configurable = object_0 as IConfigurable;
			if (configurable != null)
			{
				JsonSettings settings = configurable.Settings;
				if (settings != null)
				{
					Configuration.Instance.AddSettings(settings);
				}
			}
		}

		public static void smethod_1(object object_0)
		{
			IConfigurable configurable = object_0 as IConfigurable;
			if (configurable != null)
			{
				JsonSettings settings = configurable.Settings;
				if (settings != null)
				{
					Configuration.Instance.RemoveSettings(settings);
				}
			}
		}

		public static bool smethod_2(long long_0, string string_0, FormatType formatType)
		{
			foreach (CustomDeckCache customDeck in MainSettings.Instance.CustomDecks)
			{
				if (customDeck.DeckId == long_0 && customDeck.Name.Equals(string_0) && customDeck.FormatType == formatType)
				{
					return false;
				}
			}
			return true;
		}

		public static void smethod_3()
		{
			MainSettings.Instance.CustomDecks.Clear();
			MainSettings.Instance.Save();
		}

		public static void smethod_4()
		{
			try
			{
				CollectionDeckTray collectionDeckTray = CollectionDeckTray.Get();
				if (collectionDeckTray == null)
				{
					return;
				}
				foreach (TraySection traySection in collectionDeckTray.m_decksContent.m_traySections)
				{
					CollectionDeckBoxVisual deckBox = traySection.m_deckBox;
					long deckID = deckBox.GetDeckID();
					string text = deckBox.m_deckName.Text;
					FormatType formatType = deckBox.m_formatType;
					if (deckID == -1 || !deckBox.IsValid())
					{
						continue;
					}
					CustomDeckCache customDeckCache = null;
					bool flag = true;
					foreach (CustomDeckCache customDeck in MainSettings.Instance.CustomDecks)
					{
						if (customDeck.DeckId == deckID)
						{
							customDeckCache = customDeck;
							customDeckCache.Name = text;
							customDeckCache.FormatType = formatType;
							customDeckCache.Save();
							flag = false;
							break;
						}
					}
					if (customDeckCache == null)
					{
						customDeckCache = new CustomDeckCache(deckID)
						{
							DeckId = deckID,
							HeroCardId = deckBox.m_heroCardID,
							Name = deckBox.GetDeckNameText().Text,
							FormatType = formatType
						};
					}
					CollectionDeck deck = CollectionManager.Get().GetDeck(deckID);
					if (!deck.m_netContentsLoaded)
					{
						if (customDeckCache.CardIds.Count == 30 && flag)
						{
							MainSettings.Instance.CustomDecks.Add(customDeckCache);
						}
						continue;
					}
					customDeckCache.CardIds.Clear();
					foreach (CollectionDeckSlot slot in deck.m_slots)
					{
						for (int i = 0; i < slot.Count; i++)
						{
							customDeckCache.CardIds.Add(slot.CardID);
						}
					}
					customDeckCache.Save();
					if (flag)
					{
						MainSettings.Instance.CustomDecks.Add(customDeckCache);
						MainSettings.Instance.Save();
					}
				}
			}
			catch (Exception)
			{
				MainSettings.Instance.CustomDecks.Clear();
				MainSettings.Instance.Save();
				throw;
			}
		}

		static Utility()
		{
			ilog_0 = Triton.Common.LogUtilities.Logger.GetLoggerInstanceForType();
			Random = new Random();
		}
	}
}
